package logic

import (
	"an_ju_ke/myrpc/myrpc"
	"context"

	"an_ju_ke/myapi/internal/svc"
	"an_ju_ke/myapi/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type SupplyLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSupplyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SupplyLogic {
	return &SupplyLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SupplyLogic) Supply(req *types.SupplyRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	supply, err := l.svcCtx.UserRpc.Supply(l.ctx, &myrpc.SupplyRequest{
		Id:    int64(req.Id),
		Age:   int64(req.Age),
		From:  req.From,
		EMail: req.EMail,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "修改成功",
		Data:    supply,
	}, nil
}
